package com.baichang.taoshunda.service.impl;

import com.alipay.api.AppPay;
import com.alipay.util.AlipayUtil;
import com.baichang.framework.excelption.ServiceException;
import com.baichang.framework.utils.MathUtils;
import com.baichang.taoshunda.dao.UserRechargeHistoryDao;
import com.baichang.taoshunda.entity.User;
import com.baichang.taoshunda.entity.UserRechargeHistory;
import com.baichang.taoshunda.entity.em.UserRechargeHistoryType;
import com.baichang.taoshunda.service.*;
import com.baichang.taoshunda.utils.ListGroupByTime;
import com.baichang.taoshunda.weixin.tencent.WeixinUtils;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.qianmi.open.api.ApiException;
import com.qianmi.open.api.DefaultOpenClient;
import com.qianmi.open.api.OpenClient;
import com.qianmi.open.api.request.*;
import com.qianmi.open.api.response.*;
import net.sf.json.JSONObject;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by ${wushenglu} on 2018/1/30.
 */
@Service
public class ServiceLifeServiceImpl implements ServiceLifeService {
    protected static String url = "http://api.bm001.com/api";
    protected static String appKey = "10001319";
    protected static String appSecret = "gUjpChpSnyrEr4RdURxtyx695kLE70Ar";
    protected static String accessToken = "b82b2e4c9a3f424d910980e469fdd5de";
    OpenClient client = new DefaultOpenClient(url, appSecret);
    @Autowired
    private UserRechargeHistoryService userRechargeHistoryService;
    @Autowired
    private UserRechargeHistoryDao userRechargeHistoryDao;
    @Autowired
    private UserAccountService userAccountService;

    @Autowired
    private PensionService pensionService;
    @Autowired
    private UserService userService;

    /**
     * 非必选步骤，查询单个话费充值商品：
     * 1.返回指定面值，手机号所在区域下优先级最高商品，优先级："市>省>全国，固定面值>任意充"
     * 2.在同样充值金额下，满足客户选择不同商品需求，可选择与 "查询话费直充商品列表"接口分场景使用
     * 3.可放弃此步骤，直接根据手机号码、充值金额直接生成订单(知道商品编号的前提下)。
     *
     * @param mobileNo       手机号
     * @param rechargeAmount 充值金额
     * @return
     */
    @Override
    public Map<String, Object> getMobileItemInfo(String mobileNo, String rechargeAmount) throws ServiceException {
        Map<String, Object> map = new HashedMap();
        BmRechargeMobileGetItemInfoRequest req = new BmRechargeMobileGetItemInfoRequest();
        req.setMobileNo(mobileNo);
        req.setRechargeAmount(rechargeAmount);
        try {
            BmRechargeMobileGetItemInfoResponse response = client.execute(req, accessToken);
            JSONObject responseGetBody = JSONObject.fromObject(response.getBody().toString());
            if (responseGetBody.get("mobile_item_info_get_response") == null) {
                JSONObject mobileItemInfoGetResponse = JSONObject.fromObject(responseGetBody.get("error_response").toString());
                throw new ServiceException(mobileItemInfoGetResponse.get("sub_msg").toString() + "，请及时联系客服！");
            }
            JSONObject mobileItemInfoGetResponse = JSONObject.fromObject(responseGetBody.get("mobile_item_info_get_response").toString());
            JSONObject mobileItemInfo = JSONObject.fromObject(mobileItemInfoGetResponse.get("mobileItemInfo").toString());
            //itemId 商品编号
            map.put("itemId", mobileItemInfo.get("itemId").toString());
            //inPrice 商品进价，单位元，保留2位小数
            map.put("inPrice", mobileItemInfo.get("inPrice").toString());
            //可购买的数量
            map.put("numberChoice", mobileItemInfo.get("numberChoice").toString());
            //号码信息-省
            map.put("province", mobileItemInfo.get("province").toString());
            //号码信息-市
            map.put("city", mobileItemInfo.get("city").toString());
            //	运营商
            map.put("operator", mobileItemInfo.get("operator").toString());
            //商品名称
            map.put("itemName", mobileItemInfo.get("itemName").toString());
            //	充值金额，单位元，保留2位小数
            map.put("rechargeAmount", mobileItemInfo.get("rechargeAmount").toString());
            //advicePrice 零售价，单位元，保留2位小数
            map.put("advicePrice", mobileItemInfo.get("advicePrice").toString());
            //	手机号码
            map.put("mobileNo", mobileItemInfo.get("mobileNo").toString());
            //	是否支持冲正 1 支持 0 不支持
            map.put("reverseFlag", mobileItemInfo.get("reverseFlag").toString());
        } catch (ApiException e) {
            e.printStackTrace();

        }
        System.out.print(map);
        return map;
    }

    /**
     * 电话费充值
     *
     * @param mobileNo           手机号
     * @param rechargeAmount     充值金额
     * @param payMethod          支付方式
     * @param itemId             商品编号
     * @param userId             用户编号
     * @param isDiscount         是否优惠
     * @param preferentialAmount 优惠金额
     * @param userName           用户名称
     * @param type
     * @return
     */
    @Override
    public Map<String, Object> createdMobileBill(String mobileNo, String rechargeAmount, int payMethod, String itemId, int userId, int isDiscount, Double preferentialAmount, String userName, int type) throws ServiceException {
        Map map = new HashMap();
        BigDecimal totalMoney;
        long userRechargeId = userRechargeHistoryService.saveRechargeHistory(userId, isDiscount, payMethod, preferentialAmount, mobileNo, rechargeAmount, itemId, userName, UserRechargeHistoryType.valueOfCode(type).name());

        UserRechargeHistory history = userRechargeHistoryDao.getEntityById(userRechargeId);
//    .subtract(BigDecimal.valueOf(Double.valueOf(preferentialAmount)))
        totalMoney = BigDecimal.valueOf(Double.valueOf(preferentialAmount));
        String title = UserRechargeHistoryType.valueOfCode(type).name() + "总付款：" + totalMoney + "元";

        if (payMethod == 1) {
            //支付宝
            String aplipay = AppPay.createPay(title, history.getPayOrderKid(), title, totalMoney.doubleValue());//这里传的是支付订单编号
            map.put("pay", aplipay);
        } else if (payMethod == 2) {
            String paykid = history.getPayOrderKid();
            int money = totalMoney.multiply(BigDecimal.valueOf(100)).intValue();
            map = WeixinUtils.getPayInfo(title, money, paykid);
        }
        map.put("userRechargeId", userRechargeId);
        return map;
    }

    /**
     * 手机话费充值
     *
     * @param userRechargeId 订单记录编号
     * @return
     * @throws ServiceException
     */
    @Override
    public Map<String, Object> payMobileBill(int userRechargeId) throws ServiceException {
        Map<String, Object> map = new HashedMap();
        UserRechargeHistory history = userRechargeHistoryDao.getEntityById(userRechargeId);
        //添加成功
        if (history != null) {
            BmRechargeMobilePayBillRequest req = new BmRechargeMobilePayBillRequest();
            req.setMobileNo(history.getAccount());
            req.setRechargeAmount(history.getAmount().toString());
            req.setOuterTid(history.getOrderNumber().toString());
            try {
                BmRechargeMobilePayBillResponse response = client.execute(req, accessToken);
                JSONObject responseGetBody = JSONObject.fromObject(response.getBody().toString());
                //{"pay_bill_response":{"orderDetailInfo":{"orderCost":"9.975","orderProfit":"0.025","saleAmount":"10.000","cardPasswords":{"cardPassword":null},"orderTime":"2018-01-31 10:49:27","operateTime":null,"payState":"1","rechargeState":"0","supQq":null,"classType":"4","itemCost":"9.975","supId":"S115281","supNickName":null,"supContactUser":null,"supMobile":null,"billId":"S1801313050200","itemId":"151799","itemNum":"1","rechargeAccount":"18553468807","gameArea":null,"gameServer":null,"receiveMobile":null,"actPrice":null,"extPay":null,"itemName":"山东联通话费10元直充","isBatch":null,"outerTid":null,"userCode":"A1795483","battleAccount":null,"openBank":null,"cardNo":null,"customerName":null,"customerTel":null,"purchaser":null,"buyerTel":null,"buyerAddress":null,"buyerRemark":null,"minConsume":null,"packageName":null,"preStore":null,"idNo":null,"idAddress":null,"idFrontImage":null,"idBackImage":null,"remark":null,"simCardId":null,"mobileNo":null,"tplId":"00010001"}}}

                if (responseGetBody.get("pay_bill_response") == null) {
                    JSONObject mobileItemInfoGetResponse = JSONObject.fromObject(responseGetBody.get("error_response").toString());
                    throw new ServiceException(mobileItemInfoGetResponse.get("sub_msg").toString() + "，请及时联系客服！");
                }
                JSONObject payBillResponse = JSONObject.fromObject(responseGetBody.get("pay_bill_response").toString());
                JSONObject orderDetailInfo = JSONObject.fromObject(payBillResponse.get("orderDetailInfo").toString());
                map.put("orderDetailInfo", orderDetailInfo.toString());
                //rechargeState	String	1	订单充值状态 0充值中 1成功 9撤销
                map.put("rechargeState", orderDetailInfo.get("rechargeState").toString());
                //rechargeAccount	String	2314234243	充值账号
                map.put("rechargeAccount", orderDetailInfo.get("rechargeAccount").toString());
                //	订单处理时间，格式：yyyy-MM-dd hh:mm:ss
                map.put("operateTime", orderDetailInfo.get("operateTime").toString());
                //	itemName	String	100话费快充	商品名称
                map.put("itemName", orderDetailInfo.get("itemName").toString());
                orderDetailInfo.get("saleAmount").toString();
                System.out.println("充值返回" + responseGetBody.toString());
                if (orderDetailInfo.get("rechargeState").toString().equals("9")) {
                    boolean isTrue;
                    if (history.getPayMethod() == 1) {
                        isTrue = AlipayUtil.refundMoney(history.getPayOrderKid(), history.getPreferentialAmount().doubleValue());
                    } else {
                        isTrue = WeixinUtils.payMallRefund(history.getPayOrderKid(), (int) MathUtils.mul(history.getPreferentialAmount().doubleValue(), 100D), (int) MathUtils.mul(history.getPreferentialAmount().doubleValue(), 100D));
                    }
                } else {
                    if (orderDetailInfo.get("rechargeState").toString().equals("1")) {
                        userRechargeHistoryService.updateStatus(1, orderDetailInfo.get("itemName").toString(), userRechargeId);
                    } else {
                        userRechargeHistoryService.updateStatus(0, orderDetailInfo.get("itemName").toString(), userRechargeId);
                    }
                    User user = userService.getUserBeanById(history.getUserId());
                    if (user != null) {
                        if (user.getIsCertificate() == 1) {
                            pensionService.savePension(history.getUserId(), history.getRechargeType(), 2, history.getAccount(),
                                    history.getOrderNumber(), history.getAmount().divide(BigDecimal.valueOf(1000), 3),
                                    history.getAmount(), history.getAmount().divide(BigDecimal.valueOf(1000), 3),
                                    1, 0, history.getPayMethod(), "", BigDecimal.valueOf(0), 0);

                        }
                    }
                }

            } catch (ApiException e) {
                e.printStackTrace();
            }
        } else {
            throw new ServiceException("充值失败");
        }
        return map;
    }

    @Override
    public Map<String, Object> waterCoalList(int pageNo, int pageSize, String province, String city, int userId, String itemName, String projectId) throws ServiceException {
        Map<String, Object> map = new HashedMap();
        BmDirectRechargeWaterCoalItemListRequest req = new BmDirectRechargeWaterCoalItemListRequest();
        req.setCity(city);
        req.setProjectId(projectId);
        if (itemName != "") {
            req.setItemName(itemName);
        }
        List<Map<String, Object>> account = new ArrayList<>();
        try {
            BmDirectRechargeWaterCoalItemListResponse response = client.execute(req, accessToken);
            JSONObject responseGetBody = JSONObject.fromObject(response.getBody().toString());
            if (responseGetBody.get("admin_item_response") == null) {
                JSONObject mobileItemInfoGetResponse = JSONObject.fromObject(responseGetBody.get("error_response").toString());
                throw new ServiceException(mobileItemInfoGetResponse.get("sub_msg").toString() + "，请联系客服！");
            }
            JSONObject mobileItemInfoGetResponse = JSONObject.fromObject(responseGetBody.get("admin_item_response").toString());
            if (mobileItemInfoGetResponse.get("totalCount").toString().equals("0")) {
                throw new ServiceException("你查询的机构暂未开通服务！");
            } else {
                JSONObject mobileItemInfo = JSONObject.fromObject(mobileItemInfoGetResponse.get("items").toString());
                List<Map<String, Object>> list = new Gson().fromJson(mobileItemInfo.getString("item"), new TypeToken<List<Map<String,
                        Object>>>() {
                }.getType());
                map.put("items", list);
            }
            account = userAccountService.getUserAccount(UserRechargeHistoryType.水电煤充值.getCode(), userId);
            map.put("account", account);
        } catch (ApiException e) {
            e.printStackTrace();
        }
        return map;
    }

    @Override
    public Map<String, Object> waterCoalPyBill(String itemId, String payPrice, String rechargeAccount,
                                               int userRechargeId, int userId, int type) throws ServiceException {
        Map<String, Object> map = new HashedMap();
        BmDirectRechargeLifeRechargePayBillRequest req = new BmDirectRechargeLifeRechargePayBillRequest();
        UserRechargeHistory history = userRechargeHistoryDao.getEntityById(userRechargeId);
        req.setItemId(itemId);
        req.setItemNum(payPrice);
        req.setRechargeAccount(rechargeAccount);
        req.setOuterTid(history.getOrderNumber());
        try {
            BmDirectRechargeLifeRechargePayBillResponse response = client.execute(req, accessToken);
            JSONObject responseGetBody = JSONObject.fromObject(response.getBody().toString());
            if (responseGetBody.get("pay_bill_response") == null) {
                JSONObject mobileItemInfoGetResponse = JSONObject.fromObject(responseGetBody.get("error_response").toString());
                throw new ServiceException(mobileItemInfoGetResponse.get("sub_msg").toString() + "，请联系客服！");
            }
            JSONObject mobileItemInfoGetResponse = JSONObject.fromObject(responseGetBody.get("pay_bill_response").toString());
            JSONObject mobileItemInfo = JSONObject.fromObject(mobileItemInfoGetResponse.get("orderDetailInfo").toString());
            map.put("items", mobileItemInfo.toString());
            int isAdd = userAccountService.getUserAccountByAccount(userId, rechargeAccount);
            if (isAdd == 0) {
                userAccountService.saveAccount(userId, rechargeAccount, UserRechargeHistoryType.水电煤充值.getCode(), type);
            }
            userRechargeHistoryService.updateStatus(1, mobileItemInfo.get("itemName").toString(), userRechargeId);
        } catch (ApiException e) {
            e.printStackTrace();
        }
        return map;
    }

    @Override
    public Map<String, Object> waterCoalItemPropsList(String itemId) throws ServiceException {
        Map<String, Object> map = new HashedMap();
        BmDirectRechargeWaterCoalItemPropsListRequest req = new BmDirectRechargeWaterCoalItemPropsListRequest();
        req.setItemId(itemId);
        try {
            BmDirectRechargeWaterCoalItemPropsListResponse response = client.execute(req, accessToken);
            JSONObject responseGetBody = JSONObject.fromObject(response.getBody().toString());
            if (responseGetBody.get("item_props_list_response") == null) {
                JSONObject mobileItemInfoGetResponse = JSONObject.fromObject(responseGetBody.get("error_response").toString());
                throw new ServiceException(mobileItemInfoGetResponse.get("sub_msg").toString() + "，请联系客服！");
            }
            JSONObject mobileItemInfoGetResponse = JSONObject.fromObject(responseGetBody.get("item_props_list_response").toString());
            JSONObject mobileItemInfo = JSONObject.fromObject(mobileItemInfoGetResponse.get("itemProps").toString());
            List<Map<String, Object>> list = new Gson().fromJson(mobileItemInfo.getString("itemProp"), new TypeToken<List<Map<String,
                    Object>>>() {
            }.getType());
            map.put("cid", response.getCid());
            map.put("itemId", mobileItemInfoGetResponse.get("itemId"));
            map.put("itemProps", list);
        } catch (ApiException e) {
            e.printStackTrace();
        }
        return map;
    }

    @Override
    public Map<String, Object> getAccountInfo(String itemId, String account, String projectId, String
            unitId, String province, String unitName, String cityId, String modeId, String city) throws ServiceException {
        Map<String, Object> map = new HashedMap();
        try {
            BmDirectRechargeWaterCoalGetAccountInfoRequest req = new BmDirectRechargeWaterCoalGetAccountInfoRequest();
            req.setItemId(itemId);
            req.setAccount(account);
            req.setProjectId(projectId);
            req.setUnitId(unitId);
            req.setProvince(province);
            req.setCity(city);
            req.setUnitName(unitName);
            req.setCityId(cityId);
            req.setModeType("2");
            req.setModeId(modeId);
            BmDirectRechargeWaterCoalGetAccountInfoResponse response = client.execute(req, accessToken);
            JSONObject responseGetBody = JSONObject.fromObject(response.getBody().toString());
            if (responseGetBody.get("water_coal_ubqs_response") == null) {
                JSONObject mobileItemInfoGetResponse = JSONObject.fromObject(responseGetBody.get("error_response").toString());
                throw new ServiceException(mobileItemInfoGetResponse.get("sub_msg").toString() + "，请联系客服！");
            }
            JSONObject mobileItemInfoGetResponse = JSONObject.fromObject(responseGetBody.get("water_coal_ubqs_response").toString());
            JSONObject mobileItemInfo = JSONObject.fromObject(mobileItemInfoGetResponse.get("waterCoalBills").toString());
            List<Map<String, Object>> list = new Gson().fromJson(mobileItemInfo.getString("waterCoalBill"), new TypeToken<List<Map<String,
                    Object>>>() {
            }.getType());
            map.put("waterCoalBill", list);
        } catch (ApiException e) {
            e.printStackTrace();
        }
        return map;
    }

    /**
     * 加油卡信息
     *
     * @param province  加油卡归属省份名称(不包含"省"，如"江苏","全国")
     * @param operator  加油卡供应商名称,中石化sinopec,中石油cnpc
     * @param gasCardNo 加油卡卡号
     * @return
     * @throws ServiceException
     */
    @Override
    public Map<String, Object> gasCardGetAccountInfo(String province, String operator, String gasCardNo) throws
            ServiceException {
        Map<String, Object> map = new HashedMap();
        BmGasCardGetAccountInfoRequest req = new BmGasCardGetAccountInfoRequest();
        req.setProvince(province);
        req.setOperator(operator);
        req.setGasCardNo(gasCardNo);
        try {
            BmGasCardGetAccountInfoResponse response = client.execute(req, accessToken);
            JSONObject responseGetBody = JSONObject.fromObject(response.getBody().toString());
            if (responseGetBody.get("gas_card_ubqs_response") == null) {
                JSONObject mobileItemInfoGetResponse = JSONObject.fromObject(responseGetBody.get("error_response").toString());
                throw new ServiceException(mobileItemInfoGetResponse.get("sub_msg").toString() + "，请联系客服！");
            }
            JSONObject mobileItemInfoGetResponse = JSONObject.fromObject(responseGetBody.get("gas_card_ubqs_response").toString());
            JSONObject mobileItemInfo = JSONObject.fromObject(mobileItemInfoGetResponse.get("gasCardInfo").toString());
            map.put("cardNo", mobileItemInfo.get("cardNo"));
            map.put("cardState", mobileItemInfo.get("cardState"));
        } catch (ApiException e) {
            e.printStackTrace();
        }
        return map;
    }

    @Override
    public Map<String, Object> gasCardList() throws ServiceException {
        Map<String, Object> map = new HashedMap();
        BmGasCardItemListRequest req = new BmGasCardItemListRequest();

        try {
            BmGasCardItemListResponse response = client.execute(req, accessToken);
            JSONObject responseGetBody = JSONObject.fromObject(response.getBody().toString());
            if (responseGetBody.get("admin_item_response") == null) {
                JSONObject mobileItemInfoGetResponse = JSONObject.fromObject(responseGetBody.get("error_response").toString());
                throw new ServiceException(mobileItemInfoGetResponse.get("sub_msg").toString() + "，请联系客服！");
            }
            JSONObject mobileItemInfoGetResponse = JSONObject.fromObject(responseGetBody.get("admin_item_response").toString());
            JSONObject mobileItemInfo = JSONObject.fromObject(mobileItemInfoGetResponse.get("items").toString());
            List<Map<String, Object>> list = new Gson().fromJson(mobileItemInfo.getString("item"), new TypeToken<List<Map<String,
                    Object>>>() {
            }.getType());
            map.put("gasCardList", list);
        } catch (ApiException e) {
            e.printStackTrace();
        }
        return map;
    }

    @Override
    public Map<String, Object> gasCardPayBill(String itemId, String gasCardTel, String gasCardName, String
            gasCardNo, String userRechargeId) throws ServiceException {
        Map<String, Object> map = new HashedMap();
        BmGasCardPayBillRequest req = new BmGasCardPayBillRequest();
        UserRechargeHistory history = userRechargeHistoryDao.getEntityById(userRechargeId);
        req.setItemId(itemId);
        req.setGasCardTel(gasCardTel);
        req.setGasCardName(gasCardName);
        req.setGasCardNo(gasCardNo);
        req.setOuterTid(history.getOrderNumber());
        try {
            //{"pay_bill_response":{"orderDetailInfo":{"orderCost":"100.000","orderProfit":"0.000","saleAmount":"100.000","cardPasswords":{"cardPassword":null},"orderTime":"2018-02-06 10:37:51","operateTime":null,"payState":"1","rechargeState":"0","supQq":null,"classType":null,"itemCost":"100.000","supId":"S115281","supNickName":null,"supContactUser":null,"supMobile":null,"billId":"S1802066442146","itemId":"64357111","itemNum":"1","rechargeAccount":"1000113700009316792","gameArea":null,"gameServer":null,"receiveMobile":null,"actPrice":null,"extPay":null,"itemName":"全国   中石化加油卡    直充100元","isBatch":null,"outerTid":null,"userCode":"A1795483","battleAccount":null,"openBank":null,"cardNo":null,"customerName":null,"customerTel":null,"purchaser":null,"buyerTel":null,"buyerAddress":null,"buyerRemark":null,"minConsume":null,"packageName":null,"preStore":null,"idNo":null,"idAddress":null,"idFrontImage":null,"idBackImage":null,"remark":null,"simCardId":null,"mobileNo":null,"tplId":"00040006"}}}
            BmGasCardPayBillResponse response = client.execute(req, accessToken);
            JSONObject responseGetBody = JSONObject.fromObject(response.getBody().toString());
            if (responseGetBody.get("pay_bill_response") == null) {
                JSONObject mobileItemInfoGetResponse = JSONObject.fromObject(responseGetBody.get("error_response").toString());
                throw new ServiceException(mobileItemInfoGetResponse.get("sub_msg").toString() + "，请联系客服！");
            }
            JSONObject mobileItemInfo = JSONObject.fromObject(responseGetBody.get("pay_bill_response").toString());
            JSONObject orderDetailInfo = JSONObject.fromObject(mobileItemInfo.get("orderDetailInfo").toString());
            //itemId 商品编号
            map.put("itemId", orderDetailInfo.get("itemId").toString());
            //inPrice 商品进价，单位元，保留2位小数
            map.put("inPrice", orderDetailInfo.get("saleAmount").toString());
            //商品名称
            map.put("itemName", orderDetailInfo.get("itemName").toString());
            //	充值账号
            map.put("rechargeAccount", orderDetailInfo.get("rechargeAccount").toString());
            int isAdd = userAccountService.getUserAccountByAccount(history.getUserId(), gasCardNo);
            if (isAdd == 0) {
                userAccountService.saveAccount(history.getUserId(), gasCardNo, UserRechargeHistoryType.油卡充值.getCode(), 0);
            }
            userRechargeHistoryService.updateStatus(1, orderDetailInfo.get("itemName").toString(), Integer.parseInt(userRechargeId));
        } catch (ApiException e) {
            e.printStackTrace();
        }
        return map;
    }

    /**
     * 查询充值记录
     *
     * @param userId
     * @param type
     * @param nowPage
     * @param pageSize
     * @return
     */
    @Override
    public List<Map<String, Object>> getUserRechargeHistory(int userId, int type, int nowPage, int pageSize) {
        List<Map<String, Object>> historyList = userRechargeHistoryService.getUserRechargeHistory(userId, UserRechargeHistoryType.valueOfCode(type).name(), nowPage, pageSize);
        return ListGroupByTime.groupByDateList(historyList, "created");
    }

}
